package com.cy.detectsys.util;

import java.util.Base64;
import java.util.UUID;


public class UUIDUtil {

    private static final int UUID_LENGTH = 128 >> 3;

    private static final int HALF_LENGTH = 64 >> 3;

    private static final int BYTE_MASK = (1 << 8) - 1;

    public static String createUUID() {
        UUID uuid = UUID.randomUUID();
        long high = uuid.getMostSignificantBits();
        long low = uuid.getLeastSignificantBits();

        byte[] byteUUID = new byte[UUID_LENGTH];
        for (int i = 0; i < HALF_LENGTH; i++) {
            byteUUID[i] = (byte) (high >>> (HALF_LENGTH * (7 - i)) & BYTE_MASK);
            byteUUID[i + HALF_LENGTH] = (byte) (low >>> (HALF_LENGTH * (7 - i)) & BYTE_MASK);
        }

        return Base64.getUrlEncoder().withoutPadding().encodeToString(byteUUID);
    }


}
